package com.zttek.photosShareProject.modules.web.share;

import com.zttek.photosShareProject.common.base.MyBaseController;
import com.zttek.photosShareProject.common.json.ShareVO;
import com.zttek.photosShareProject.modules.model.Share;
import com.zttek.photosShareProject.modules.service.login.IUserService;
import com.zttek.photosShareProject.modules.service.share.IRankService;
import com.zttek.photosShareProject.modules.service.share.IShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Y
 * Date: 2017-09-07
 * Time: 11:39
 */
@RequestMapping("/rank")
@Controller
public class RankController extends MyBaseController {

    @Autowired
    private IRankService rankService;

    @Autowired
    private IShareService shareService;

    @RequestMapping(value = "/day", method = RequestMethod.GET)
    @ResponseBody
    public Object getDayRank(@RequestParam("userId") Long userId) throws Exception {
        List<Long> longs = rankService.Rank2List(rankService.selectRankDay(rankService.getDayNum()));
        List<Share> shares = shareService.selectShareByIdList(longs);
        List<ShareVO> shareVOs = shareService.share2VO(shares, userId, false);
        return renderSuccess(shareVOs);
    }

    @RequestMapping(value = "/week", method = RequestMethod.GET)
    @ResponseBody
    public Object getWeekRank(@RequestParam("userId") Long userId) throws Exception {
        List<Long> longs = rankService.Rank2List(rankService.selectRankWeek(rankService.getWeekNum()));
        List<Share> shares = shareService.selectShareByIdList(longs);
        List<ShareVO> shareVOs = shareService.share2VO(shares, userId, false);
        return renderSuccess(shareVOs);
    }

    @RequestMapping(value = "/month", method = RequestMethod.GET)
    @ResponseBody
    public Object getMonthRank(@RequestParam("userId") Long userId) throws Exception {
        List<Long> longs = rankService.Rank2List(rankService.selectRankMonth(rankService.getMonthNum()));
        List<Share> shares = shareService.selectShareByIdList(longs);
        List<ShareVO> shareVOs = shareService.share2VO(shares, userId, false);
        return renderSuccess(shareVOs);
    }

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public Object getAllRank(@RequestParam("userId") Long userId) throws Exception {
        List<Long> longs = rankService.Rank2List(rankService.selectRankAll());
        List<Share> shares = shareService.selectShareByIdList(longs);
        List<ShareVO> shareVOs = shareService.share2VO(shares, userId, false);
        return renderSuccess(shareVOs);
    }
}
